<template>
<view>
<form @reset="formReset" @submit="makeimg" reportSubmit="true" v-if="!cvtype">
    <view class="page_modle">
        <view class="page_modle_top">
            <view class="page_modle_topview"></view>
            <image class="page_modle_topImg" :src="carsimg"></image>
        </view>
        <image class="erweima" :src="qrcodeimg"></image>
        <view class="tishi">{{qrstr}}</view>
        <button class="btn" form-type="submit">立即生成</button>
    </view>
    <view class="left_dian"></view>
    <view class="left_dian_sec"></view>
</form>
<view v-if="cvtype">
    <canvas canvasId="show" style="margin:0 auto;width: 370px; height: 530px;background-color:#fff;"></canvas>
    <button @tap="makeinimg" class="btn">保存推广图片</button>
</view>
</view>
</template>

<script>
var app = getApp();

export default {
  data() {
    return {
      cvtype: !1,
      headimg: "",
      headtemp: "",
      carsimg: "",
      carstemp: "",
      qrcodeimg: "",
      qrcodetemp: "",
      nickname: "",
      propaganda1: "我正在使用“小程序”",
      propaganda11: "平台交易车",
      propaganda2: "快来看看我要买卖的车辆吧!",
      qrstr: "扫描上方二维码,进入小程序买卖二手车!",
      makeinnum: 1,
      enddelimg: [],
      loaddata: "",
      isShow: !1
    };
  },

  components: {},
  props: {},
  onLoad: function (a) {
    var t = this;
    app.globalData.util.getUserInfo(function (a) {
      a.memberInfo ? t.reload() : t.setData({
        isShow: !0
      });
    });
  },
  onShow: function () {},
  onReady: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {},
  onShareAppMessage: function () {},
  methods: {
    hideDialog: function () {
      this.setData({
        isShow: !this.isShow
      });
    },
    updateUserInfo: function (a) {
      var t = this;
      app.globalData.util.getUserInfo(function (a) {
        wx.setStorageSync("uid", a.memberInfo.uid), t.hideDialog(), t.reload();
      }, a.detail);
    },
    reload: function () {
      var t = this,
          a = t.loaddata;
      app.globalData.util.request({
        url: "entry/wxapp/Api",
        data: {
          m: "monai_market",
          carid: a.id,
          uid: wx.getStorageSync("uid"),
          r: "sale.index.getcarimg"
        },
        cachetime: "0",
        success: function (a) {
          "" != a.data.data.carimg ? wx.downloadFile({
            url: t.backimg(a.data.data.carimg),
            success: function (a) {
              console.log(a), t.carstemp = a.tempFilePath;
            },
            fail: function () {
              t.carstemp = "/static/pages/image/store_bg.png";
            }
          }) : t.carstemp = "/static/pages/image/store_bg.png", wx.downloadFile({
            url: t.backimg(a.data.data.qrcode),
            success: function (a) {
              console.log(a), t.qrcodetemp = a.tempFilePath;
            },
            fail: function () {
              t.qrcodetemp = a.data.data.qrcode;
            }
          }), t.setData({
            propaganda1: "我正在使用“" + a.data.data.info.name,
            propaganda11: "小程序”平台交易车",
            headimg: a.data.data.headimg,
            carsimg: a.data.data.carimg ? a.data.data.carimg : "/static/pages/image/store_bg.png",
            qrcodeimg: a.data.data.qrcode
          });
        },
        fail: function (a) {
          wx.showModal({
            content: a.data.message,
            success: function () {
              5e3 == a.data.error && t.setData({
                isShow: !0
              }), wx.navigateBack({});
            }
          });
        }
      });
    },
    backimg: function (a) {
      return app.globalData.util.url("entry/wxapp/Api", {
        m: "monai_market",
        img: a,
        r: "sale.index.getthecarimg"
      });
    },
    makeinimg: function () {
      wx.showLoading({
        title: "正在保存图片..."
      });
      var t = this;
      1 < t.makeinnum || (t.makeinnum = 2, wx.canvasToTempFilePath({
        canvasId: "show",
        success: function (a) {
          wx.saveImageToPhotosAlbum({
            filePath: a.tempFilePath,
            success: function () {
              t.makeinnum = 1, console.log("成功");
            },
            fail: function () {
              t.makeinnum = 1, console.log("shibai ");
            }
          });
        }
      }), setTimeout(function () {
        wx.hideLoading();
      }, 1e3));
    },
    makeimg: function (a) {
      var t = this,
          e = wx.createCanvasContext("show", t);
      wx.canvasPutImageData({
        canvasId: "show",
        x: 0,
        y: 0,
        width: 375,
        height: 530,
        success: function (a) {}
      }), e.setFillStyle("#DDDDDD"), e.fillRect(0, 0, 370, 530), e.rect(15, 25, 340, 490), e.setFillStyle("#FFFFFF"), e.fill();
      var i = t.carstemp;
      e.drawImage(i, 15, 25, 340, 200);
      var n = t.qrcodetemp;
      e.drawImage(n, 110, 270, 150, 150), e.font = "normal normal 13px SimHei", e.setFillStyle("#666666"), e.setTextAlign("center"), e.fillText(t.qrstr, 185, 450), e.save(), e.beginPath(), e.arc(15, 224, 12, 0, 2 * Math.PI), e.setFillStyle("#DDDDDD"), e.fill(), e.clip(), e.restore(), e.save(), e.beginPath(), e.arc(355, 224, 12, 0, 2 * Math.PI), e.setFillStyle("#DDDDDD"), e.fill(), e.clip(), e.restore(), t.setData({
        cvtype: !0
      }), wx.drawCanvas({
        canvasId: "show",
        actions: e.getActions()
      });
    },

    formReset() {
      console.log("占位：函数 formReset 未声明");
    }

  }
};
</script>
<style>
@import "./index.css";
</style>